package org.example.bobofish.user.application.facade;

import org.example.bobofish.user.application.facade.entity.GetUserRightsListResponse;
import org.example.bobofish.user.application.facade.entity.LockUserRightsRequest;
import org.example.bobofish.user.application.facade.map.UserFacadeMapper;
import org.example.bobofish.user.domain.model.UserRightsInfoModel;
import org.example.bobofish.user.domain.service.UserRightsService;
import org.example.bobofish.common.exception.BizException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author : yuxiong
 * @date : 2025/6/17
 */
@Component
public class UserFacade {

    @Autowired
    private UserRightsService userRightsService;

    public GetUserRightsListResponse getUserRightsList(String userId) {
        List<UserRightsInfoModel> userRightsList = userRightsService.getUserRightsList(userId);
        return UserFacadeMapper.INSTANCE.convert(userRightsList);
    }

    public boolean operateRights(LockUserRightsRequest userRightsRequest) {
        try {
            userRightsService.operateRights(userRightsRequest);
            return true;
        } catch (Exception e) {
            return e instanceof BizException;
        }
    }

}
